<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>轮播图</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        img {
            vertical-align: top;
        }

        /*取消图片底部3像素距离*/
        .box {
            width: 600px;
            height: 300px;
            margin: 100px auto;
            background-color: pink;
            position: relative;
            overflow: hidden;
        }

        .box ul {
            width: 600%;
            position: absolute;
            left: 0;
            top: 0;
        }

        .box ul li {
            float: left;
        }

        .box ul li img {
            height: 300px;
            /* width: 600px; */
        }

        /* ![img](http://qinniu.douziqianduan.icu/20201203215939) */
    </style>
</head>

<body>
    <div class="box" id="scroll">
        <ul>
            <li><img src="http://qinniu.douziqianduan.icu/wallpaper01.jpg" alt="" /></li>
            <li><img src="http://qinniu.douziqianduan.icu/wallpaper02.jpg" alt="" /></li>
            <li><img src="http://qinniu.douziqianduan.icu/wallpaper03.jpg" alt="" /></li>
            <li><img src="http://qinniu.douziqianduan.icu/wallpaper04.jpg" alt="" /></li>
            <li><img src="http://qinniu.douziqianduan.icu/wallpaper05.jpg" alt="" /></li>
            <li><img src="http://qinniu.douziqianduan.icu/wallpaper06.jpg" alt="" /></li>
        </ul>
    </div>
</body>

</html>
<script>
    let scroll = document.getElementById("scroll");

    let ul = scroll.children[0];

    let num = 0; //控制左侧值  left

    let timer = null; // 定时器

    // 自动播放
    function autoPlay() {
        num--;
        num <= -2400 ? num = 0 : num;
        ul.style.left = num + "px";
    }

    // 鼠标经过大盒子  停止定时器
    scroll.onmouseover = function () {
        clearInterval(timer);
    }

    // 鼠标划出盒子
    scroll.onmouseout = function () {
        timer = setInterval(autoPlay, 10); // 开启定时器
    }

    timer = setInterval(autoPlay, 10);
</script>